﻿<!DOCTYPE html>
<html style="font-family: shnormal;">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>正在加载请稍候...</title>
    <style>
        iframe {
            border: none;
            width: 100%
        }
    </style>
    <script src="../Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
    <!--表单样式-->
    <link href="../Admin/CSS/FoolFrmBody.css" rel="stylesheet" />
    <!-- layui -->
    <link href="../Scripts/layui/layui/css/layui.css" rel="stylesheet" />
    <link href="../Scripts/layui/style/admin.css" rel="stylesheet" />
    <link href="../Scripts/layui/layui/css/autocomplete.css" rel="stylesheet" />
    <script src="../Scripts/layui/layui/layui.js" type="text/javascript"></script>
    <script src="../Scripts/layui/LayuiDialog.js" type="text/javascript"></script>
    <!--通用的JS-->
    <script src="../Scripts/config.js" type="text/javascript"></script>
    <script src="../Comm/Gener.js" type="text/javascript"></script>
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="./JS/tinymce/tinymce.min.js"></script>
    <script src="./JS/jspdf.debug.js" charset="utf-8"></script>
    <script src="./JS/html2canvas.min.js"></script>
    <!--<script src="../../DataUser/ThirdpartySoftware/fonts/jspdf.customfonts.min.js"></script>
    <script src="../../DataUser/ThirdpartySoftware/fonts/default_vfs.js"></script>-->
    <script src="ChapterFrmGener.js"></script>
    <script language="javascript" type="text/javascript">

        layui.use(['tree', 'dropdown', 'form', 'jquery'], function () {
            var $ = layui.jquery;
            var frmID = null;
            var oid = null;
            var key = GetQueryString('attrKey');
            var group = [];
            //页面启动函数.
            $(function () {

                frmID = GetQueryString("FrmID");
                oid = GetQueryString("WorkID");
                if (oid == null)
                    oid = GetQueryString("OID");


                var handler = new HttpHandler("BP.WF.HttpHandler.WF_CCForm");
                handler.AddPara("FrmID", frmID);
                handler.AddPara("OID", oid);
                var data = handler.DoMethodReturnJSON("ChapterFrm_Init");

                var groupFields = data["GroupFields"];//章.
                var attrs = data["MapAttrs"];//节.

                //获得第一个Key值.
                GenerFistKey(key, groupFields, attrs);


                //形成数据.
                for (var i = 0; i < groupFields.length; i++) {
                    var gf = groupFields[i];
                    gf.children = [];
                    var list = {
                        title: gf.Lab,
                        id: gf.FrmID,
                        field: gf.Lab,
                        spread: true,
                        children: gf.children,
                        checked: false,
                        ...gf
                    }
                    for (var idx = 0; idx < attrs.length; idx++) {
                        var attr = attrs[idx];
                        var clist = {
                            title: attr.Name,
                            id: attr.KeyOfEn,
                            field: attr.Name,
                            checked: false,
                            pName: gf.Lab,
                            ...attr
                        }

                        if (clist.GroupID == list.OID) {
                            list.children.push(clist)
                        }

                    }
                    group.push(list)
                }
                addHtml(group);
                //$("#pdf_btn").on('click', function () {
                //    $("#header").hide();
                //    $(".athClass").hide(); 
               // });
                fromHTML();
                //setTimeout(function () { fromHTML() }, 5000);
                
            });


            //获得从表的url.
            function Ele_Dtl(frmID) {
                var frmDtl = new Entity("BP.Sys.MapDtl", frmID);
                var src = "";
                var href = GetHrefUrl();
                var urlParam = href.substring(href.indexOf('?') + 1, href.length);
                urlParam = urlParam.replace('&DoType=', '&DoTypeDel=xx');

                var ensName = frmDtl.No;
                if (ensName == undefined) {
                    layer.alert('系统错误,请找管理员联系');
                    return;
                }

                var currentURL = GetHrefUrl();

                var baseUrl = "./";
                if (currentURL.indexOf("AdminFrm.htm") != -1)
                    baseUrl = "../../CCForm/";
                if (currentURL.indexOf("MyBill.htm") != -1 || currentURL.indexOf("MyDict.htm") != -1)
                    baseUrl = "../CCForm/";
                if (currentURL.indexOf("FrmGener.htm") != -1 || currentURL.indexOf("FrmDBVer.htm") != -1 || currentURL.indexOf("DtlFrm.htm") != -1)
                    baseUrl = "./";

                //表格模式
                if (frmDtl.ListShowModel == "0")
                    src = baseUrl + "Dtl2017.htm?1=1";
                if (frmDtl.ListShowModel == "1")
                    src = baseUrl + "DtlCard.htm?1=1";
                if (frmDtl.ListShowModel == "2") {
                    if (frmDtl.UrlDtl == null || frmDtl.UrlDtl == undefined || frmDtl.UrlDtl == "")
                        return "从表" + frmDtl.Name + "没有设置URL,请在" + frmDtl.FK_MapData + "_Self.js中解析";
                    src = basePath + "/" + frmDtl.UrlDtl;
                    if (src.indexOf("?") == -1)
                        src += "?1=1";
                }

                src += "&EnsName=" + frmDtl.No + "&RefPKVal=" + oid + "&FK_MapData=" + frmID + "&IsReadonly=1&" + urlParam + "&Version=1&FrmType=0";
                return src;

            }

            function ChapterFrmShow(attrKey) {
                InitPara();
                if (attrKey == null || attrKey == "") {
                    alert("字段值为空.");
                    return;
                }
                var handler = new HttpHandler("BP.WF.HttpHandler.WF_CCForm");
                handler.AddPara("FrmID", frmID);
                handler.AddPara("OID", oid);
                handler.AddPara("KeyOfEn", attrKey);
                var data = handler.DoMethodReturnString("ChapterFrm_InitOneField");
                return data
            }

            function addHtml(group) {
                group.forEach((item, index) => {
                    var html = `<div class="layui-card" id="card_${index}">
                                                                                                                                                        <div class="layui-card-header" id="head_${index}">
                                                                                                                                                           <h3 style="font-weight: bolder;">${item.title}</h3>
                                                                                                                                                        </div>
                                                                                                                                                </div>`
                    $("#cBody").append(html);
                    if (item.children.length > 0) {
                        item.children.forEach((ite, idx) => {
                            var d = ChapterFrmShow(ite.KeyOfEn);
                            var cby = `<div class="layui-card-body">
                                                                                                                                                    <h4>${idx + 1}.${ite.title}</h4>
                                                                                                                                                    <p>${d}</p>
                                                                                                                                                   </div>`
                            $("#card_" + index).append(cby);
                        })

                    } else {
                        if (item.CtrlType == "Dtl") {
                            var url = Ele_Dtl(item.CtrlID);
                            var ifrm = `<iframe src='${url}' id="ifrm_${index}"></iframe>`
                            $("#card_" + index).append(ifrm);
                            var testFrame = document.getElementById('ifrm_' + index);
                            testFrame.addEventListener('load', function () {
                                testFrame.height = getHeight(testFrame.contentDocument);
                                let iframeBody = testFrame.contentWindow.document.body.innerHTML;
                                $("#card_" + index).append(iframeBody);
                                $("#ifrm_" + index).hide();
                            });
                        }

                        if (item.CtrlType == "Ath") {
                            var url = basePath + "/WF/CCForm/Ath.htm?1=1&AthPK=" + item.CtrlID + "&RefPKVal=" + oid + "&FK_MapData=" + frmID + "&IsReadonly=1";
                            var ifrm1 = `<iframe src='${url}' id="ifrm_${index}"></iframe>`
                            $("#card_" + index).append(ifrm1);
                            var testFrame = document.getElementById('ifrm_' + index);
                            testFrame.addEventListener('load', function () {
                                testFrame.height = getHeight(testFrame.contentDocument);
                                let iframeBody = testFrame.contentWindow.document.body.innerHTML;
                                $("#card_" + index).append(iframeBody);
                                $("#card_" + index).addClass('athClass');
                                $("#ifrm_" + index).hide();
                            });
                        }

                        if (item.CtrlType == "ChapterFrmLinkFrm") {
                            var url = basePath + "/WF/CCForm/Frm.htm?IsReadonly=1&FrmID=" + item.CtrlID + "&OID=" + oid + "&FK_MapData=" + item.CtrlID + "&FK_Node=" + GetQueryString("FK_Node");
                            var ifrm2 = `<iframe src='${url}' id="ifrm_${index}"></iframe>`
                            $("#card_" + index).append(ifrm2);
                            var testFrame = document.getElementById('ifrm_' + index);
                            testFrame.addEventListener('load', function () {
                                testFrame.height = getHeight(testFrame.contentDocument);
                                let iframeBody = testFrame.contentWindow.document.body.innerHTML;
                                $("#card_" + index).append(iframeBody);
                                $("#ifrm_" + index).hide();
                            });
                        }

                        if (item.CtrlType == "ChapterFrmSelfUrl") {
                            var url = '';
                            if (item.CtrlID.indexOf('http') == 0) {
                                var url = item.CtrlID + "&OID=" + oid + "&FK_MapData=" + frmID + "&FK_Node=" + GetQueryString("FK_Node") + "&IsReadonly=1";
                            } else {
                                var url = basePath + "" + item.CtrlID + "&OID=" + oid + "&FK_MapData=" + frmID + "&FK_Node=" + GetQueryString("FK_Node") + "&IsReadonly=1";
                            }
                            var ifrm3 = `<iframe src='${url}' id="ifrm_${index}"></iframe>`
                            $("#card_" + index).append(ifrm3);
                            var testFrame = document.getElementById('ifrm_' + index);
                            testFrame.addEventListener('load', function () {
                                testFrame.height = getHeight(testFrame.contentDocument);
                                let iframeBody = testFrame.contentWindow.document.body.innerHTML;
                                $("#card_" + index).append(iframeBody);
                                $("#ifrm_" + index).hide();
                            });
                        }
                    }
                });
            }


        })

    </script>

</head>
<body id="pdf_container">
    <div class="layui-row padding-5">
        <div class="layui-col-sm12 layui-col-md12 layui-col-xs12">
            <div class="layui-card">
                <!--<div class="layui-card-header" id="header">
                    <div class="layui-right" id="pdf_btn">
                        <button class="layui-btn layui-btn-sm layui-btn-normal">打印</button>
                    </div>
                </div>-->
                <div class="layui-card-body conventionReport" id="cBody">
                </div>
            </div>
        </div>
    </div>
</body>
</html>